package com.itheima.springboottilasmanager.survice.deptsurvice;

import com.itheima.springboottilasmanager.mapper.EmpMapper;
import com.itheima.springboottilasmanager.mapper.StudentMapper;
import com.itheima.springboottilasmanager.pojo.dto.GenderCount;
import com.itheima.springboottilasmanager.pojo.dto.Jobcount;
import com.itheima.springboottilasmanager.pojo.dto.StudentCount;
import com.itheima.springboottilasmanager.pojo.vo.JobVO;
import com.itheima.springboottilasmanager.pojo.vo.StudentVO;
import com.itheima.springboottilasmanager.survice.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ReportSimp implements ReportService {


    @Autowired
    EmpMapper empMapper;
    @Autowired
    StudentMapper studentMapper;
    @Override
    public JobVO empJobReport() {
   List<Jobcount> jobcountlist = empMapper.countByJob();
//   处理查询结果，封装成JobVo
     List<Integer> joblist =   jobcountlist.stream().map(jc->jc.getCount()).collect(Collectors.toList());
     List<String> jobname =   jobcountlist.stream().map(jc->jc.getJob()).collect(Collectors.toList());
        return new JobVO(jobname,joblist);
    }
    @Override
    public List<GenderCount> empGenderReport() {
      List<GenderCount> list =  empMapper.countByGender();
      return list;
    }
    @Override
    public List<GenderCount> studentDegreeReport() {

        List<GenderCount> list =  studentMapper.countByDegree();
        return list;
    }

    @Override
    public StudentVO studentCountReport() {
        List<StudentCount> list= studentMapper.studentCountReport();
          List<String> clazzList = list.stream().map(StudentCount::getClazzName).toList();
          List<Integer> dataList = list.stream().map(StudentCount::getCount).toList();
        return new StudentVO(clazzList,dataList);
    }}

